﻿@using hc.epm.DataModel.Basic;
@model List<Base_User>
@{
    ViewBag.Title = "SelectUsers";
}


<div class="content-right date-wrap fl c" style="min-height:100px;margin-left:10px">
    <div class="search mt5">
        <form class="layui-form" action="" method="get">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" style="width:100px">名称 : </label>
                    <div class="layui-input-inline"><input type="text" name="name" id="name" placeholder="请输入名称" autocomplete="off" class="layui-input" value="@ViewBag.Name" /></div>
                </div>
                @*<input type="hidden" name="IsMultiple" id="IsMultiple" value=@ViewBag.IsMultiple />*@
                <input type="hidden" name="companyId" id="companyId" value=@ViewBag.CompanyId />
                <input type="submit" class="layui-btn layui-btn-radius layui-btn-warm" lay-filter="search" value="搜 索" />
            </div>
        </form>
    </div>
</div>
<div class="main mt5" style="margin:0 10px">
    <div class="layui-form">
        <table class="layui-table">
            <thead>
                <tr>
                    <th width="6%" style="text-align:center">
                        <input type="checkbox" lay-skin="primary" lay-filter="allChoose" />
                    </th>
                    <th width="60" class="table-center">序号</th>
                    <th width="18%" class="table-center">用户账户</th>
                    <th class="table-center">用户名称</th>
                    <th class="table-center">用户编码</th>
                    <th class="table-center">手机号</th>
                </tr>
            </thead>
            <tbody id="selectData">
                @{
                    int index = 0;
                }
                @if (Model != null && Model.LongCount() > 0)
            {
                foreach (var item in Model)
                {
                    index++;
                        <tr>
                            <td style="text-align:center">
                                <input type="checkbox" name="selectUser" value="@item.SId" data-username="@item.UserName" data-phone="@item.Phone" lay-skin="primary" />
                                <input type="hidden" name="ids" id="id-@item.SId" value="@item.SId" />
                            </td>
                            <td class="table-center">@index </td>
                            <td class="table-center">@item.UserAcct</td>
                            <td class="table-center">@item.UserName</td>
                            <td class="table-center">@item.UserCode</td>
                            <td class="table-center">@item.Phone</td>
                        </tr>
                    }
                }
                else
                {
                    <tr>
                        <td colspan="8" class="table-center">
                            暂无数据
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>

    <div id="page">
        <div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-1">
            <a href="javascript:;" class="layui-laypage-prev layui-disabled" data-page="0">上一页</a>
            <span class="layui-laypage-curr"><em class="layui-laypage-em"></em><em>1</em></span>
            <a href="javascript:;" class="layui-laypage-next layui-disabled" data-page="2">下一页</a>
            <span class="layui-laypage-skip">
                到第<input type="text" min="1" value="1" class="layui-input">页
                <button type="button" class="layui-laypage-btn">确定</button>
            </span>
            <span class="layui-laypage-count">共 6 条</span>
        </div>
    </div>
</div>

<script type="text/javascript">

    layui.use(['layer', 'form', 'element', 'laypage'], function () {
        var layer = layui.layer, form = layui.form, element = layui.element, $ = layui.jquery, laypage = layui.laypage;
        //分页
        laypage.render({
            elem: 'page',
            count: '@ViewBag.Total',
            curr: '@ViewBag.pageIndex',
            layout: ['prev', 'page', 'next', 'skip', 'count', ],
            jump: function (obj, first) {
                if (!first) {
                    //得到了当前页，用于向服务端请求对应数据
                    var curr = obj.curr;
                    var search = $("form").serialize();
                    window.location.href = "/Common/SelectUser?pageIndex=" + curr + "&" + search;
                }
            }
        });
        form.on('checkbox(allChoose)', function (data) {
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
            child.each(function (index, item) {
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });
    });

    function getSelectIds() {
            selectId = [];
        $('#selectData :checkbox[name="selectUser"]:checked').each(function (index) {
            selectId.push({ Id: $(this).val() || ''});
        });
        return selectId;
    }

    function getSelectData() {
        var getSelections = $('#selectData :checkbox[name="selectUser"]:checked'),
            selectData = [];
        $.each(getSelections, function(index, item) {
                selectData.push({
                    Id: $(item).val() || '',
                    UserName: $(item).data('username') || '',
                    Phone: $(item).data('phone') || ''
                });
        });
        return selectData;
    }
</script>